﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Chronos;
using QxFramework.Core;
using QxFramework.Utilities;
using System;

[CreateAssetMenu(menuName = "skill")]
public class K_HeaveyAttack : SkillBase
{
    //public CharaBase Player;
    public RigidbodyTimeline2D rb;
    public float damageRatio = 1;
    
    public override void Init(EntityBase user)
    {
        base.Init(user);
        ColdDownInit();

        rb = User.time.rigidbody2D;

        MessageManager.Instance.Get<K_HvyAtk_Event>().RegisterHandler(K_HvyAtk_Event.Stop, Stop);
        MessageManager.Instance.Get<K_HvyAtk_Event>().RegisterHandler(K_HvyAtk_Event.Damage, Damage);
        //Debug.Log("init attack");
    }
    public override void FixedUpdate()
    {
        if(!isColddown)
        {
            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                Debug.Log("attack");
                rb.velocity = Vector2.zero;
                User.ChangeState(States.K_HeaveyAttackState);
                //EffectManager.Instance.PlayEffect("K_HeaveyAttack", "base", Player.transform.position, Player.parameter.MovementData.moveDir);
                EffectManager.Instance.InstantiateSkillEffect("K_HeaveyAttack", EffectManager.Instance.transform.GetChild(0), User.transform.position, this);
                //Debug.Log(Player.transform.position);

                isColddown = true;
            }
        }

        ColdDownCheck();
    }
    public void Stop(object sender, EventArgs args)
    {
        User.ChangeState(States.StandState);
    }
    public void Damage(object sender, EventArgs args)
    {
        if (args is AttackInfo arg)
        {
            foreach(EntityBase enemy in arg.targets)
            {
                if(enemy.tag == "Enemy")
                enemy.parameter.HealthData.currentHealth -= User.parameter.StatusPointData.attack * damageRatio;
            }
        }
            //var enemys = Physics2D.BoxCastAll(Player.transform.position, new Vector2(1,1), 0,Player.parameter.MovementData.moveDir);
        Debug.Log("hit!");
    }
    
    
}
public enum K_HvyAtk_Event
{
    Damage,
    Stop,
}
